// Every Picture In The Universe 0.1
// Started by Vander 'imerso' Nunes on July 2012
// To contact me: imerso@imersiva.com
//
// Given enough time, generates every possible
// image for a given resolution -- which includes all your
// pictures in the past, present and future, plus
// you playing guitar together with David Gilmour
// on Rock in Rio, etc.
// OK, that may take a few billion years depending
// on the selected image resolution, but hey,
// one day that will happen -- hmm well, I guess.
//
// license: http://opensource.org/licenses/lgpl-2.1
//
// Although it seems like the program is just
// randomizing pixels, this is definitely not
// the case. A linear loop is too boring,
// so I'm trying to create alternative ways
// of permute color combinations in more
// interesting ways. Some may be buggy at
// first, but eventually this will combine
// using interesting, dynamic patterns
// until something meaninful happens.
//
// Hope you get the idea.
//
// most obvious enhancements:
//
// - a start dialog to select options
// - mono and grayscale support (for way faster permutations)
// - a time control to skip directly to a given time
// - pause the simulation
// - save both the 'time' and the generated image.

#ifndef __DEFINES_H_

	#define __DEFINES_H_

	#ifndef NULL
	#ifdef __cplusplus
	#define NULL    0
	#else
	#define NULL    ((void *)0)
	#endif
	#endif

	#ifndef FALSE
	#define FALSE               0
	#endif

	#ifndef TRUE
	#define TRUE                1
	#endif


	#ifndef BYTE
		typedef unsigned long		DWORD;
		typedef int							BOOL;
		typedef unsigned char		BYTE;
		typedef unsigned short	WORD;
		typedef float						FLOAT;
	#endif


	#define FloatToFixed16(X)			((int32) ((X) * 65536))
	#define f16(X)			            ((int32) ((X) * 65536))
	#define ITOX(i) ((i) << 16)
	#define XTOI(i) ((i) >> 16)

	//#define XMUL(a,b) ((int)(((long)a*(long)b)>>16))
	#define XMUL(a,b) ((int)( ((float)a/65536.0f)*((float)b/65536.0f) * 65536 ))	// ### SLOWWWWWWWW method...

	#define min3(a,b,c)					(min(min(a,b),c))
	#define max3(a,b,c)					(max(max(a,b),c))

  #define CLAMP(v,l,h)      ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
	#define clamp(a,b,c) ((b) >= (c) ? (a)=(b) : (a) < (b) ? (a)=(b) : (a) > (c) ? (a)=(c) : (a))

	#define rnd(a,b) ((b-(a))*((long double) rand()/32767)+(a))

	//
	// 3D Bounding Box
	//
	typedef struct
	{
		float MinX,MinY,MinZ;
		float MaxX,MaxY,MaxZ;
		float MidX,MidY,MidZ;
	} BBOX3D;


	//
	// 2D Bounding Box
	//
	typedef struct
	{
		float MinX,MinY;
		float MaxX,MaxY;
	} BBOX2D;

	// box to box or frustum relations
	typedef enum _boxrelation_e
	{
		BOX_INSIDE,
		BOX_OUTSIDE,
		BOX_INTERSECTING
	} boxrelation_e;

#endif
